<template>
  <div class="home">

    <el-container>
      <!-- 左侧列表 -->
       <el-aside width="aoto">
        <div class="logo"></div>
        <el-menu default-active="" class="el-menu-admin" @open="handleOpen" @close="handleClose" background-color="#545c64" text-color="#fff" active-text-color="#ffd04b" :unique-opened='true' :collapse='islable' :router='true'>
          <el-submenu :index="v.path"  v-for="(v) in menusList" :key='v.id'>
            <template slot="title">
              <i class="el-icon-view"></i>
              <span>{{v.authName}}</span>
            </template>
            <!--  v-for='(v2) in v.children.authName' :key='v2.id'  -->
            <el-menu-item :index='v2.path' v-for='(v2) in v.children' :key='v2.id'>
              <template slot="title" >
                <i class="el-icon-location"></i>
                <span> {{v2.authName}}</span>
              </template>
            </el-menu-item>
          </el-submenu>
        </el-menu>
      </el-aside>
      <!-- 右侧列表 -->
      <el-container>
        <el-header>
           <span class="myicon myicon-menu toggle-btn" @click="islable=!islable"></span>
          <span class="system-title">后台管理中心</span>
          <div>
            <!-- <span class="welcome">用户：{{$store.getters.getusername?$store.getters.getusername:$store.state.username}}</span> -->
            <span class="welcome">用户：{{$store.state.username?$store.state.username:$store.getters.getUserName}}</span>
            <el-button type="text" @click="loginout">退出</el-button>
          </div>
        </el-header>
        <el-main>
           <!-- 欢迎使用后台管理系统 -->
          <router-view></router-view>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script>
import { getMenus } from '../api/index.js'
export default {
  data () {
    return {
      islable: false,
      menusList: []
      // username: ''
    }
  },
  methods: {
    getusername () {
      // this.username = localStorage.getItem('myusername')
    },
    // 退出
    loginout () {
      localStorage.removeItem('mytoken')
      localStorage.removeItem('myusername')
      this.$router.push({ name: 'Login' })
    },

    handleOpen (key, keyPath) {
      console.log(key, keyPath)
    },

    handleClose (key, keyPath) {
      console.log(key, keyPath)
    }
  },
  mounted () {
    this.getusername()
    getMenus().then(res => {
      this.menusList = res.data.data
    })
  }
}
</script>

<style lang="scss" scoped>
.home {
  height: 100%;
  .el-menu-admin:not(.el-menu--collapse) {
    width: 200px;
    min-height: 400px;
  }
  .el-container {
    height: 100%;
  }
  .el-aside {
    background-color: #545c64;
  }
  .el-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background-color: #545c64;
  }
  .logo {
    height: 60px;
    background: url(../assets/logo.png);
    background-size: cover;
    background-color: #e9e9e9;
  }
  .toggle-btn {
    padding: 0 15px;
    margin-left: -20px;
    font-size: 36px;
    color: white;
    cursor: pointer;
    line-height: 60px;
    &:hover {
      background-color: #4292cf;
    }
  }
  .system-title {
    font-size: 28px;
    color: white;
  }
  .welcome {
    color: white;
  }
}
</style>
